package com 
{
	import com.managers.FontManager;
	import flash.text.TextFormat;
	/**
	 * ...
	 * @author Matthew Ladouceur
	 */
	public class Skill extends FlaText
	{
		private var _data:Object;
		private var _cost:Number = -1;
		private var _level:Number = 1;
		private var _name:String;
		public var _currentClass:String = "";
		
		private var _extraText:FlaText;
		
		public function get cost():Number {
			return _cost;
		}
		
		public function get data():Object {
			return _data;
		}
		
		public override function get name():String {
			var nameOutput:String;
			
			if (_extraText != null && _extraText.text != "") {
				if (_name == "Slay/Parry: Master") {
					nameOutput = "Slay/Parry: " + _extraText.text;
				}else if (_name == "Specialization +1: Group") {
					nameOutput = "Specialization +1: " + _extraText.text;
				}else if (_name == "Specialization +1: Specific") {
					nameOutput = "Specialization +1: " + _extraText.text;
				}else if (_name == "Weapon Proficiency: Exotic") {
					nameOutput = "Weapon Proficiency: " + _extraText.text;
				}else if (_name == "Critical +2: Specific") {
					nameOutput = "Critical +2: " + _extraText.text;
				}else if (_name == "Critical +2: Group") {
					nameOutput = "Critical +2: " + _extraText.text;
				}else if (_name == "Execute: Master") {
					nameOutput = "Execute: " + _extraText.text;
				}else if (_name == "Sphere of Magic: 1st") {
					nameOutput = "1st Sphere of Magic: " + _extraText.text;
				}else if (_name == "Sphere of Magic: 2nd") {
					nameOutput = "2nd Sphere of Magic: " + _extraText.text;
				}else if (_name == "Sphere of Magic: 3rd") {
					nameOutput = "3rd Sphere of Magic: " + _extraText.text;
				}else if (_name == "Create (Sphere) Familiar") {
					nameOutput = "Create " + _extraText.text + " Familiar";
				}else{
					nameOutput = _name + ": " + _extraText.text;
				}
			}else{
				nameOutput = _name;
			}
			
			return nameOutput;
		}
		public override function set name(value:String):void {
			_name = value;
			_name = value;
			_text.text = _name + " " + cost.toString();
		}
		
		public function get level():Number {
			return _level;
		}
		public function set level(value:Number):void {
			if (_data == null){
				_cost = _cost / _level * value;
			}
			_level = value;
			if (_data != null) {
				updateCost(_currentClass);
			}
			
			if (_level > 1){
				_text.text = "Lv. " + _level + ": " + _name + " " + cost.toString();
			}else {
				_text.text = _text.text = _name + " " + cost.toString();
			}
		}
		
		public function Skill(data:Object, cost:Number = -1, name:String = "", level:Number = 1) 
		{
			super("", new TextFormat(FontManager.Default, 14));
			_level = level;
			_text.background = true;
			_text.backgroundColor = 0xeeeeee;
			_data = data;
			_cost = cost;
			if (name != "") {
				_name = name;
			}else {
				_name = _data.@name;
			}
			width = 400;
			
			if (cost > 0) {
				_text.text = _name + " " + cost.toString();
			}else{
				_text.text = _name;
			}
			
			if (_name == "Craftsmen" || _name == "Sphere of Magic: 1st" || _name == "Sphere of Magic: 2nd" || _name == "Sphere of Magic: 3rd"
				|| _name == "Slay/Parry" || _name == "Slay/Parry: Master" || _name == "Specialization +1: Group" || _name == "Specialization +1: Specific" 
				|| _name == "Weapon Proficiency: Exotic" || _name == "Weapon Refocus" || _name == "Critical +2: Specific" || _name == "Critical +2: Group" 
				|| _name == "Execute" || _name == "Execute: Master" || _name == "Create (Sphere) Familiar") {
				_extraText = new flaInputText();
				_extraText.size = 10;
				_extraText.y = 5;
				_extraText.x = _text.x + _text.textWidth + 35;
				_extraText.width = 75;
				_extraText.height = 15;
				_extraText.border = true;
				addChild(_extraText);
			}
		}
		
		public function updateCost(string:String):void {
			_currentClass = string;
			if (_data != null){
				switch (string.toLowerCase()) {
					case "mercenary":
						_cost = _data.mercenary * _level;
						break;
					case "templar":
						_cost = _data.templar * _level;
						break;
					case "ranger":
						_cost = _data.ranger * _level;
						break;
					case "nightblade":
						_cost = _data.nightblade * _level;
						break;
					case "assassin":
						_cost = _data.assassin * _level;
						break;
					case "witch hunter":
						_cost = _data.witchhunter * _level;
						break;
					case "mage":
						_cost = _data.mage * _level;
						break;
					case "druid":
						_cost = _data.druid * _level;
						break;
					case "bard":
						_cost = _data.bard * _level;
						break;
				}
			}
			if (_level > 1){
				_text.text = "Lv. " + _level + ": " + _name + " " + cost.toString();
			}else {
				_text.text = _text.text = _name + " " + cost.toString();
			}
			
		}
		
	}

}